var loading_icon = "<img class=\"loading_icon\" src=\"image/loading_icon.gif\" />";
var tabs_locked = false;
var submitting = false;

$(function() {
	var current_open_group = -1;
	
	$( "#birthdate" ).datepicker({
		altField: "#birthdate",
		altFormat: "yy-mm-dd",
		dateFormat: "yy-mm-dd",
		changeMonth: true,
		changeYear: true,
		monthNamesShort: ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月'],
		dayNamesMin: ['月', '火', '水', '木', '金', '土', '日'],
		defaultDate: '1990-01-01'
	});
	
	if ($("#profile_unfilled").val() == "true") {
		tabs_locked = true;
		$( "#tabs").tabs("option", "disabled", [0, 2]);
	}
});

function submitProfile() {
	if (!submitting) {
		submitting = true;
		$("#profileLoading").show();
		
		name = $("#name").val();
		email = $("#email").val();
		date = $("#birthdate").val();
		
		data = "post_data=true&action=profile";
		data+= "&name=" + encodeURI(name);
		data+= "&email=" + encodeURI(email);
		data+= "&birthdate=" + encodeURI(date);
	
		$.ajax({
			type: "POST",
			url: "ajax.php",
			data: data,
			success: function (result) {
				if (result == "success") {
					hideError();
					showMessage("プロフィールを更新しました。");
					
					if (tabs_locked) {
						tabs_locked = false;
						$( "#tabs").tabs("option", "disabled", []);
						disableFunctionsTab();
					}
				}
				else
					showError(result);
				
				$("#profileLoading").hide();
				submitting = false;
				
			}
		});
	}
}


function closeBox(){
	document.getElementById('message').style.display = "none";
}
